#ifndef _PARTED_BUFFER_H
#define _PARTED_BUFFER_H

#include <ds/list.h>

/**
 * @brief Parted buffer.
 * A buffer that can combine multiple buffers into a single one.
 * At some point the io request will be scheduled in different memory space
 * so we need to keep track of the physical address of each buffer
 * that's why we need the paddr field.
 */
typedef struct parted_buffer {
    lnode_t part;
    void* data;
    void* paddr; // physical address, for DMA
    size_t size;
    size_t acc_size;
} pbuffer_t;

/**
 * @brief Add a new buffer to the list of buffers.
 * @return A pointer to the new buffer part.
 */
pbuffer_t* pbuffer_add(pbuffer_t** pb, void* data, size_t size);

void pbuffer_free(pbuffer_t* pb);

size_t pbuffer_size(pbuffer_t* pb);

#endif /* _PARTED_BUFFER_H */